﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DreamIn.Structures;

using DreamIn.Structures.Ftp;
namespace DreamIn
{
    public delegate void LoadPicturesEventHandler(Album album);
    public delegate void LoadAlbumsEventHandler();
    public enum CarouselItemType
    {
        Album,
        Picture
    }
	/// <summary>
	/// Interaction logic for CarouselItem.xaml
	/// </summary>
	public partial class CarouselItem : UserControl
	{
        public event LoadPicturesEventHandler LoadPictures;
        public event LoadAlbumsEventHandler LoadAlbums;
        private BitmapImage image;
        private Picture picture;
        private Album album;
        private CarouselItemType carouselItemType;
        private FTPFactory ftpFactory = new FTPFactory();
        ////////Constructor that might be needed.
        //public CarouselItem(BitmapImage image, Picture picture, Album album, CarouselItemType itemType)
        //{
        //    this.InitializeComponent();
        //    this.image = image;
        //    this.picture = picture;
        //    this.album = album;
        //    this.carouselItemType = itemType;
        //    this.SetControlProperties();
        //    LoadCarouseItem();
        //}
        public CarouselItem(BitmapImage image, Picture picture,Album album)
		{
			this.InitializeComponent();
            this.image = image;
            this.picture = picture;
            this.album = album;
            this.carouselItemType = CarouselItemType.Picture;
            this.SetControlProperties();
            LoadCarouseItem();
		}
        public CarouselItem(BitmapImage image, Album album)
        {
            this.InitializeComponent();
            this.image = image;
            this.album = album;
            this.carouselItemType = CarouselItemType.Album;
            this.SetControlProperties();
            LoadCarouseItem();
        }
		private void SetControlProperties()
		{
			sendButton.Opacity=0;
			driveButton.Opacity=0;
            if (this.carouselItemType == CarouselItemType.Album)
            {
                picturesButton.Visibility = Visibility.Visible;
                albumsButton.Visibility = Visibility.Hidden;
                albumsButton.Opacity = 0;
                picturesButton.Opacity = 0;
            }
            else
            {
                picturesButton.Visibility = Visibility.Hidden;
                albumsButton.Visibility = Visibility.Visible;
                albumsButton.Opacity = 0;
                picturesButton.Opacity = 0;
            }
		}
        private void LoadCarouseItem()
        {
            if (this.carouselItemType == CarouselItemType.Picture)
            {
                imageItem.BeginInit();
                imageItem.Source = image;
                imageItem.EndInit();
                labelItem.Content = picture.PictureName.ToString();
            }
            else
            {
                imageItem.BeginInit();
                imageItem.Source = image;
                imageItem.EndInit();
                labelItem.Content = album.AlbumFolderName.ToString();
            }
        }

        private void picturesButton_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
        	picturesButton.Opacity=100;
        }

        private void picturesButton_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
        	picturesButton.Opacity=0;
        }

        private void picturesButton_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (this.carouselItemType == CarouselItemType.Album)
                LoadPictures(album);
        }

        private void albumsButton_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
        	albumsButton.Opacity=100;
        }

        private void albumsButton_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
        	albumsButton.Opacity=0;
        }

        private void albumsButton_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (this.carouselItemType == CarouselItemType.Picture)
                LoadAlbums();
        }

        private void sendButton_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            
            if (this.carouselItemType == CarouselItemType.Picture)
            {
               
                ftpFactory.UploadPicture("admin", album, picture);
            }
            else if(this.carouselItemType==CarouselItemType.Album)
            {
                ftpFactory.UploadAlbum("admin", album);
            }
        }

        private void sendButton_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
        	sendButton.Opacity=100;
        }

        private void sendButton_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
        	sendButton.Opacity=0;
        }

        private void UserControl_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            
        }

        private void imageItem_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
        }

        private void driveButton_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if(this.carouselItemType==CarouselItemType.Picture)
                Process.Start("explorer.exe","/select,"+picture.PicturePath);
            else if(this.carouselItemType==CarouselItemType.Album)
                Process.Start("explorer.exe", album.AlbumPath);
            
			
        }

        private void driveButton_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
        	driveButton.Opacity=100;
        }

        private void driveButton_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
        	driveButton.Opacity=0;
        }
	}
}